#include <iostream>
#include <string>

using namespace std;

string reverseWords(string& s)
{
    int begin = 0, end = s.size();
    int pos = 0;
    while (begin != end)
    {
        if (s[begin] == ' ' || begin == end - 1)
        {
            reverse(s.begin() + pos, s.begin() + begin);
            pos = ++begin;
            continue;
        }
        ++begin;
    }
    return s;
}

int main()
{
	string s("hello world");

    string tmp = reverseWords(s);

    cout << tmp;
	return 0;
}